import { Inject } from '../decorates/inject';

@Inject()
export class PipeManage {
    protected propertys: number[];
    protected pipes: Map<string,Pipe> = new Map();
    constructor() {

    }
    public add(name: string, func: Pipe) {
        if(this.propertys.indexOf(func.property) != -1) {
            console.warn('find a same pipe property, func.property');
            return false;
        }
        this.pipes.set(name, func);
        return true;
    }
    public delete(name: string) {
        this.pipes.delete(name);
    }
    public clear() {
        this.pipes = new Map();
    }
    public getPipe(name: string): Pipe {
        let func = this.pipes.get(name);
        if(func == undefined) {
            return new defaultPipe();
        }
        return func;
    }
}
export abstract class Pipe<T = any> {
    public property: number;
    public abstract run(...param: any[]):T;
}
class defaultPipe extends Pipe {
    public property = 0;
    public run(val: any) {
        return val;
    }
}

